home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / btsys.arc / BTCLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1984-12-14  |  965 b   |  43 lines

  1. /*    btclose    */
  2. #include <stdio.h>
  3. #include <btextern.h>
  4. int btclose (filhand)
  5.  
  6. unsigned filhand;
  7.  
  8. /* close a file and free buffers */
  9. {
  10.     char *cp;
  11.     int i;
  12.  
  13. /* make sure file is open */
  14.     if (btfilar[filhand].handle == NULL)
  15.     BTSETCOD (filhand, NULL, 61);    /* file not open */
  16.  
  17. /*    write index info record it may have changed    */
  18.  
  19. /* move new root value to info index record before close */
  20.  
  21.     *(btfilar[filhand].infobuf) = btfilar[filhand].root;
  22.     movmem (btfilar[filhand].infobuf, 
  23.     btfilar[filhand].filbuf, LBLEN);
  24.     if ((i = btwrit (filhand, 0)))
  25.     BTSETCOD (filhand, 0, i);
  26.  
  27. /*    free index info buffer */
  28.     cp = (char *)btfilar[ filhand].infobuf;
  29.     free (cp);
  30.  
  31. /*    free root record buffer */
  32.     cp = (char *)btfilar[ filhand].filbuf;
  33.     free (cp);
  34.  
  35. /*    free control block    */
  36.     btfilar[filhand].handle = NULL;
  37.  
  38. /*    close file    */
  39.     fclose (btfilar[ filhand].fdesc);
  40.     return (0);
  41. }
  42. /* end of btclose */
  43.